package com.highdj.jfxdemo.controller;

import com.highdj.jfxdemo.service.PersonService;
import de.felixroske.jfxsupport.FXMLController;
import jakarta.annotation.Resource;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;

import java.net.URL;
import java.util.ResourceBundle;

@FXMLController
public class LoginController implements Initializable {
    @FXML
    private TextField txtName;
    @FXML
    private PasswordField txtPassword;
    @FXML
    private Button btnLogin;
    @FXML
    private Button btnCancel;
    @FXML
    private Text msg;

    @Resource
    public PersonService personService;

    // 在fxml中onAction的方式调用
    public void toLogin(){
        if(personService.login(txtName.getText(),txtPassword.getText())){
            msg.setText("登录成功");
        }else{
            msg.setText("登录失败");
        }
    }

    // 在initialize中采用lambda表达式调用
    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        btnCancel.setOnAction(e->{
            txtName.setText("");
            txtPassword.setText("");
            msg.setText("");
        });
    }
}
